<?php 
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: _linkProvider.phtml 5347 2010-09-07 18:16:12Z huuphuoc $
 * @since		2.0.7
 */
?>
<?php 
$this->headLink()
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.core.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.accordion.css');
	
$this->headScript()
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.core.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.accordion.js')	
?>

<div class="t_a_ui_accordion">
	<div id="linkProvider_<?php echo $this->counter; ?>">
		<?php foreach ($this->links as $route => $links) : ?>
		<h3><a href="javascript: void(0);"><?php echo $links['description']; ?></a></h3>
		<div class="t_a_bottom">
			<ul class="t_a_ui_list">
			<?php foreach ($links['links'] as $link) : ?>
				<li><a href="<?php echo $link['href']; ?>" class="t_a_ui_helper_action" route="<?php echo $route; ?>"><?php if (isset($link['title'])) : ?><?php echo $link['title']; ?><?php else : ?><?php echo $links['description']; ?><?php endif; ?></a></li>
			<?php endforeach; ?>
			</ul>
		</div>
		<?php endforeach; ?>
	</div>
</div>

<script type="text/javascript">
$(document).ready(function() {
	/**
	 * Create accordion control
	 */
	$('#linkProvider_<?php echo $this->counter; ?>').accordion({
		active: false,
		autoHeight: false,
		collapsible: true
	})
	/**
	 * @since 2.0.8
	 */
	.parent()
	.attr('viewHelperClass', 'Core_View_Helper_LinkProvider')
	.attr('viewHelperAttributes', '<?php echo Zend_Json::encode($this->attributes); ?>');

	/**
	 * Select the link handler
	 */
	<?php if ($this->attributes['jsCallback'] != null) : ?>
	$('#linkProvider_<?php echo $this->counter; ?>').find('a.t_a_ui_helper_action').click(function() {
		<?php echo $this->attributes['jsCallback'];  ?>($(this).attr('route'), $(this).attr('href'), $(this).html(),
														/**
														 * @since 2.0.8
														 */
														$(this));
		return false;
	});
	<?php endif; ?>
});
</script>
